package com.taldh.mutlithread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * date 2020/7/28
 *
 * @author 袁小黑
 * @version 1.0.0
 **/

public class FutureTaskTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable callable = () -> {
            System.out.println("true = " + Thread.currentThread().getId());
            Thread.sleep(3000);
            return "Hello world";
        };
        FutureTask futureTask = new FutureTask<>(callable);
        System.out.println("Thread.currentThread().getName() = " + Thread.currentThread().getId());
        futureTask.run();
        System.out.println("Thread.currentThread().getId() = " + Thread.currentThread().getId());
        System.out.println("futureTask = " + futureTask.get());
    }
}
